package fpga_generation.altera_nios;
import fpga_generation.java_base.*;

public class nios extends base_component
{
	base_mm_master instructionMaster;
	base_mm_master dataMaster;
	base_mm_slave jtagSlave;
	
	public static int SIZE_SMALL  = 0;
	public static int SIZE_MEDIUM = 1;
	public static int SIZE_FULL   = 2;
	
	private int addressResetVector;
	private int addressExceptionVector;
	private base_mm_slave slaveResetVector;
	private base_mm_slave slaveExceptionVector;
	
	
	int featureSize;
	
	public nios (String name, int feature)
	{
		super(name);
		this.type = "altera_nios2";
		this.clockSink = "clk";
		featureSize = feature;
		instructionMaster = new base_mm_master(name , "instruction_master", 32);
		dataMaster        = new base_mm_master(name , "data_master", 32);
		jtagSlave         = new base_mm_slave(name, "jtag_debug_module");
		
		connectInstructionMaster(jtagSlave, 0x00010800);
		connectDataMaster(       jtagSlave, 0x00010800);		
	}
	
	public void connectInstructionMaster(base_mm_slave s, int address) {
		instructionMaster.connect(s, address);
	}
	
	public void connectDataMaster(base_mm_slave s, int address) {
		dataMaster.connect(s, address);
	}
	
	public void setExceptionVector(base_mm_slave s, int address)
	{
		addressExceptionVector = address;	
		slaveExceptionVector = s;
	}
	public void setResetVector(base_mm_slave s, int address) 
	{
		addressResetVector = address;	
		slaveResetVector = s;
	}
	
	public String writeRepr(int impl, int round) {
		String outputString = "";
		if (round == 0) {
			outputString += add_module(impl);
		}
		if (round == 1) {		
			outputString += easyClockConnect();
			
			outputString += set_parameter(impl, "userDefinedSettings", "");
			outputString += set_parameter(impl, "setting_showUnpublishedSettings", false);
			outputString += set_parameter(impl, "setting_showInternalSettings", false);
			outputString += set_parameter(impl, "setting_shadowRegisterSets", 0);
			outputString += set_parameter(impl, "setting_preciseSlaveAccessErrorException", false);
			outputString += set_parameter(impl, "setting_preciseIllegalMemAccessException", false);
			outputString += set_parameter(impl, "setting_preciseDivisionErrorException", false);
			outputString += set_parameter(impl, "setting_performanceCounter", false);
			outputString += set_parameter(impl, "setting_perfCounterWidth", "_32");
			outputString += set_parameter(impl, "setting_interruptControllerType", "Internal");
			outputString += set_parameter(impl, "setting_illegalMemAccessDetection", false);
			outputString += set_parameter(impl, "setting_illegalInstructionsTrap", false);
			outputString += set_parameter(impl, "setting_fullWaveformSignals", false);
			outputString += set_parameter(impl, "setting_extraExceptionInfo", false);
			outputString += set_parameter(impl, "setting_exportPCB", false);
			outputString += set_parameter(impl, "setting_debugSimGen", false);
			outputString += set_parameter(impl, "setting_clearXBitsLDNonBypass", true);
			outputString += set_parameter(impl, "setting_branchPredictionType", "Automatic");
			outputString += set_parameter(impl, "setting_bit31BypassDCache", true);
			outputString += set_parameter(impl, "setting_bigEndian", false);
			outputString += set_parameter(impl, "setting_bhtPtrSz", "_8");
			outputString += set_parameter(impl, "setting_bhtIndexPcOnly", false);
			outputString += set_parameter(impl, "setting_avalonDebugPortPresent", false);
			outputString += set_parameter(impl, "setting_alwaysEncrypt", true);
			outputString += set_parameter(impl, "setting_allowFullAddressRange", false);
			outputString += set_parameter(impl, "setting_activateTrace", true);
			outputString += set_parameter(impl, "setting_activateTestEndChecker", false);
			outputString += set_parameter(impl, "setting_activateMonitors", true);
			outputString += set_parameter(impl, "setting_activateModelChecker", false);
			outputString += set_parameter(impl, "setting_HDLSimCachesCleared", true);
			outputString += set_parameter(impl, "setting_HBreakTest", false);

			outputString += set_parameter(impl, "muldiv_multiplierType", "EmbeddedMulFast");
			outputString += set_parameter(impl, "muldiv_divider", false);
			outputString += set_parameter(impl, "mpu_useLimit", false);
			outputString += set_parameter(impl, "mpu_numOfInstRegion", 8);
			outputString += set_parameter(impl, "mpu_numOfDataRegion", 8);
			outputString += set_parameter(impl, "mpu_minInstRegionSize", "_12");
			outputString += set_parameter(impl, "mpu_minDataRegionSize", "_12");
			outputString += set_parameter(impl, "mpu_enabled", false);
			outputString += set_parameter(impl, "mmu_uitlbNumEntries", "_4");
			outputString += set_parameter(impl, "mmu_udtlbNumEntries", "_6");
			outputString += set_parameter(impl, "mmu_tlbPtrSz", "_7");
			outputString += set_parameter(impl, "mmu_tlbNumWays", "_16");
			outputString += set_parameter(impl, "mmu_processIDNumBits", "_8");
			outputString += set_parameter(impl, "mmu_enabled", false);
			outputString += set_parameter(impl, "mmu_autoAssignTlbPtrSz", true);
			outputString += set_parameter(impl, "mmu_TLBMissExcSlave", "");
			outputString += set_parameter(impl, "mmu_TLBMissExcOffset", 0);
			outputString += set_parameter(impl, "manuallyAssignCpuID", false);
			outputString += set_parameter(impl, "impl", "Tiny");
			outputString += set_parameter(impl, "icache_size", "_4096");
			outputString += set_parameter(impl, "icache_ramBlockType", "Automatic");
			outputString += set_parameter(impl, "icache_numTCIM", "_0");
			outputString += set_parameter(impl, "icache_burstType", "None");

			outputString += set_parameter(impl, "debug_triggerArming", true);
			outputString += set_parameter(impl, "debug_level", "Level1");
			outputString += set_parameter(impl, "debug_jtagInstanceID", 0);
			outputString += set_parameter(impl, "debug_embeddedPLL", true);
			outputString += set_parameter(impl, "debug_debugReqSignals", false);
			outputString += set_parameter(impl, "debug_assignJtagInstanceID", false);
			outputString += set_parameter(impl, "debug_OCIOnchipTrace", "_128");
			outputString += set_parameter(impl, "dcache_size", "_2048");
			outputString += set_parameter(impl, "dcache_ramBlockType", "Automatic");
			outputString += set_parameter(impl, "dcache_omitDataMaster", false);
			outputString += set_parameter(impl, "dcache_numTCDM", "_0");
			outputString += set_parameter(impl, "dcache_lineSize", "_32");
			outputString += set_parameter(impl, "dcache_bursts", false);
			outputString += set_parameter(impl, "cpuReset", false);
			outputString += set_parameter(impl, "cpuID", 0);
			outputString += set_parameter(impl, "breakSlave", "cpu_0.jtag_debug_module");
			outputString += set_parameter(impl, "breakOffset", 32);
		}
		if (round == 5) {
			outputString += set_parameter(impl, "resetSlave", slaveResetVector.getInterface());
			outputString += set_parameter(impl, "resetOffset", addressResetVector);
			outputString += set_parameter(impl, "exceptionSlave", slaveExceptionVector.getInterface());
			outputString += set_parameter(impl, "exceptionOffset", addressExceptionVector);
		}
		outputString += jtagSlave.writeRepr(impl, round);
		outputString += dataMaster.writeRepr(impl, round);
		outputString += instructionMaster.writeRepr(impl, round);
		return outputString;
	}
}